﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Notepad_X.Classes {
    public static class DocumentTypes {
        static List<Type> types;

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static int getCount() { return types.Count; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static int AddType(Type t) {
            if (types == null) types = new List<Type>();
            types.Add(t);
            if(Added!=null) Added.Invoke(null, null);
            return types.Count - 1;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        public static void RemoveType(int index) {
            if (index < 0 || index + 1 > types.Count) return;
            types.RemoveAt(index);
        }

        public static IDocument CreateDocument(int index, int id) {
            return  (IDocument)Activator.CreateInstance(types[index], new object[] { id });
        }
        /// <summary>
        /// 
        /// </summary>
        public static void RemoveAll() {
            types.Clear();
        }
        /// <summary>
        /// 
        /// </summary>
        public static List<Type> getTypes { get { return types; } }
        /// <summary>
        /// 
        /// </summary>
        public static event EventHandler Added;
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static string[] getNames() {
            string[] value = new string[types.Count];
            for (int i = 0; i < types.Count; i++) {
                value[i] = types[i].Name;
            }
            return value;
        }
    }
}
